const app = getApp();
import {
    _headerPost,
    _get
} from '../../../utils/httpUtils.js'
Page({
    /**
     * 页面的初始数据
     */
    data: {
        navbarData: {
            showCapsule: 1, //是否显示左上角图标
            title: '上线大酬宾' //导航栏 中间的标题
        },
        height: app.globalData.height,
        loading: false,
        myFormat1: ['天', ':', ':', ' '],
        clearTimer: false,
        targetTime1: new Date().getTime() + 420000 //初始值
    },
    

    onLoad(option) {
        _get('/api/Activity/activity_list', {}, res => {
            this.data.loading == false
            if (res.data.code == '1') {
                this.setData({
                    activity: res.data.data.activity,
                    endTime: res.data.data.activity.being.time.end_time,
                })
                this.getEndTime();

            } else {
                wx.showToast({
                    title: '网络请求出错',
                    icon: 'none'
                })
            }
        }, '', comp => {
            wx.stopPullDownRefresh()
        })
    },

    onShow: function() {

    },
    getEndTime() { // 计时器
        let that = this;
        setInterval(function() {
            let strtime = that.data.endTime;
            let date = new Date(strtime.replace(/-/g, '/'));
            let targetTime1 = date.getTime();
            that.setData({
                targetTime1: targetTime1
            })
        }, 1000)
    },

    enterDetial(e) {
        wx.navigateTo({
            url: `/pages/activity/line001/detail?id=${e.currentTarget.dataset.id}&time=${this.data.targetTime1}`
        })
    },

    _navback() {
        wx.navigateBack()
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function() {
        this.setData({
            clearTimer: true
        });
    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function() {
        if (this.data.loading == false) {
            this.data.loading == true
            this.onLoad()
        }
    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function() {

    }
})